<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/24 0024
 * Time: 10:55
 */
use Illuminate\Http\Request;

function sendsms($mobile,$content){
    $target     = config('site.shortmsg.url');
    $usr        = config('site.shortmsg.uid');
    $pwd        = config('site.shortmsg.pass');
    $content    = iconv('UTF-8','GB2312',$content);
    $post_data  = "uid=". $usr ."&pass=".$pwd."&sjh=".$mobile."&memo=".$content."&ftype=1&sendtime=";
    $gets       = post($post_data,$target);
    $info       = explode(",",$gets);
    switch($info[0]){
        case -1:
            $msg = ['status '=>-1, 'content' => '短信平台用户名或者密码错误'];
            break;
        case -2:
            $msg = ['status'=>-2, 'content'=>'余额不足'];
            break;
        case    -3:
            $msg = ['status'=>-3, 'content'=>'发送方式错误'];
            break;
        case -4:
            $msg = ['status'=>-4, 'content'=>'定时时间有误'];
            break;
        case -5:
            $msg = ['status'=>-5, 'content'=>'手机号不能为空'];
            break;
        case -6:
            $msg = ['status'=>-6, 'content'=>'发送内容不能为空'];
            break;
        case -7:
            $msg = ['status'=>-7, 'content'=>'未知错误'];
            break;
        case -8:
            $msg = ['status'=>-8, 'content'=>'每包不能大于50个手机号'];
            break;
        case -9:
            $msg = ['status'=>-9, 'content'=>'发送失败'];
            break;
        case -10:
            $msg = ['status'=>-10, 'content'=>'内容超过三百个字符'];
            break;
        default:
            $msg = ['status'=>1, 'content'=>'已发送成功，请稍等...'];
            break;
    }
    return $msg;
}

function post($curlPost,$url){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_NOBODY, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
    $return_str = curl_exec($curl);
    curl_close($curl);
    return $return_str;
}